/*
 ------------------------------------------------------------------------------
 Copyright (C) 1996-2001 Id Software, Inc.

 This file is part of the Quake source code.

 The Quake source code is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or (at your
 option) any later version.

 The Quake source code is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 more details.

 You should have received a copy of the GNU General Public License along with
 the Quake source code; if not, write to the Free Software Foundation, Inc.,
 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 ------------------------------------------------------------------------------
*/


//
// shared.h - included first by ALL program modules
//


#ifndef __SHARED_H__
#define __SHARED_H__


#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <time.h>


/*
 ==============================================================================

 WIN32 SPECIFICS

 ==============================================================================
*/

#ifdef _WIN32

#pragma warning (disable : 4018)				// signed/unsigned mismatch
#pragma warning (disable : 4244)				// conversion from 'x' to 'x', possible loss of data
#pragma warning (disable : 4996)				// 'x' was declared deprecated

#include <windows.h>
#include <commctrl.h>
#include <intrin.h>

typedef __int64						longlong;
typedef unsigned __int64			ulonglong;

#define CPU_STRING					"x86"

#ifdef _DEBUG
#define BUILD_STRING				"Win32-x86 Debug"
#else
#define BUILD_STRING				"Win32-x86 Release"
#endif

#define PATH_SEPARATOR_STRING		"\\"
#define PATH_SEPARATOR_CHAR			'\\'

#define LIBRARY_EXTENSION			".dll"

#define NEWLINE						"\r\n"

#define INLINE						__forceinline

#define ALIGN_16(x)					__declspec(align(16)) x

#define LITTLE_ENDIAN				1
#define BIG_ENDIAN					0

#define snprintf					_snprintf
#define vsnprintf					_vsnprintf

#endif

/*
 ==============================================================================

 LINUX SPECIFICS

 ==============================================================================
*/


/*
 ==============================================================================

 MACOSX SPECIFICS

 ==============================================================================
*/


/*
 ==============================================================================

 SINGLE INSTRUCTION MULTIPLE DATA

 ==============================================================================
*/

// Undefine SIMD_X86 and SIMD_PPC to disable the SIMD code for all platforms

#if defined _M_IX86 || defined __i386__

#define SIMD_X86
#define SIMD_X86_NAME				"MMX & SSE & SSE2"
#define SIMD_X86_CPUID				(CPUID_MMX | CPUID_SSE | CPUID_SSE2)

#include <mmintrin.h>
#include <xmmintrin.h>
#include <emmintrin.h>

#elif defined __ppc__

#define SIMD_PPC
#define SIMD_PPC_NAME				"AltiVec"
#define SIMD_PPC_CPUID				(CPUID_ALTIVEC)

#include <ppc_intrinsics.h>

#endif

/*
 ==============================================================================

 SHARED TYPES AND DEFINES

 ==============================================================================
*/

typedef unsigned char				uchar;
typedef unsigned short				ushort;
typedef unsigned int				uint;
typedef unsigned long				ulong;

typedef uchar						byte;
typedef ushort						word;
typedef ulong						dword;
typedef ulonglong					qword;

typedef ushort						half;

#define false						0
#define true						1
#define bool						int

#ifndef NULL
#define NULL						((void *)0)
#endif

#ifndef BIT
#define BIT(num)					(1 << (num))
#endif

#ifndef ALIGN
#define ALIGN(size, bytes)			(((size) + ((bytes) - 1)) & ~((bytes) - 1))
#endif

#define SIZE_KB(bytes)				((bytes) >> 10)
#define SIZE_MB(bytes)				((bytes) >> 20)
#define SIZE_GB(bytes)				((bytes) >> 30)

#define SIZE_KB_FLOAT(bytes)		((bytes) * (1.0f / 1024.0f))
#define SIZE_MB_FLOAT(bytes)		((bytes) * (1.0f / 1048576.0f))
#define SIZE_GB_FLOAT(bytes)		((bytes) * (1.0f / 1073741824.0f))

template <class T> INLINE void		Swap (T &x, T &y){ T tmp = x; x = y; y = tmp; }

/*
 ==============================================================================

 SHARED HEADERS

 ==============================================================================
*/

#include "swap.h"
#include "crc.h"
#include "md4.h"
#include "string.h"
#include "infoString.h"

#include "surfaceParms.h"
#include "fileFormats.h"

#include "math/math.h"
#include "math/random.h"
#include "math/vector.h"
#include "math/angles.h"
#include "math/quaternion.h"
#include "math/matrix.h"
#include "math/bounds.h"
#include "math/sphere.h"
#include "math/plane.h"
#include "math/color.h"
#include "math/rect.h"

#include "framework/common.h"
#include "framework/memory.h"
#include "framework/fileSystem.h"
#include "framework/cmdSystem.h"
#include "framework/cvarSystem.h"
#include "framework/msgSystem.h"
#include "framework/defManager.h"
#include "framework/parser.h"
#include "framework/system.h"
#include "framework/table.h"
#include "framework/game.h"
#include "framework/collision.h"
#include "framework/renderer.h"
#include "framework/sound.h"
#include "framework/gui.h"


#endif	// ___SHARED_H__